import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input, InputNumber, Radio, Modal, Cascader, Row, Col, DatePicker, bottomLeft } from 'antd'
import moment from 'moment';
import Toggles from '../../components/Toggles';
const RangePicker = DatePicker.RangePicker;
const RadioGroup = Radio.Group;
const FormItem = Form.Item
const { TextArea } = Input;
//日期
const dateFormat = 'YYYY/MM/DD';
const formItemLayout = {
  labelCol: {
    span: 6,
  },
  wrapperCol: {
    span: 14,
  },
}

const modal = ({
  item = {},
  onOk,
  form: {
    getFieldDecorator,
    validateFields,
    getFieldsValue,
  },
  ...modalProps
}) => {
  const handleOk = () => {
    validateFields((errors) => {
      if (errors) {
        return
      }
      const data = {
        ...getFieldsValue(),
        key: item.key,
      }
      // data.address = data.address.join(' ')
      // data.backPaymentPeriod = data.backPaymentPeriod  && data.backPaymentPeriod[0],
      // data.billParty = data.billParty && data.billParty[0],
      // data.payerId = data.payerId && data.payerId[0],
      // data.reimbursementRatio = data.reimbursementRatio && data.reimbursementRatio[0]

         data.isBadRecord = data.isBadRecord && data.isBadRecord[0],//是否有不良记录

      //data.operator='admin'
      onOk(data)
    })
  }
  //补0操作
  function getzf(num){
     if(parseInt(num) < 10){
         num = '0'+num;
     }
     return num;
   }

   //时间拼接




  const modalOpts = {
    ...modalProps,
    onOk: handleOk,
  }
  return (
    <Modal {...modalOpts}>
      <Toggles name='其他信息'>
        <Row>
          <Col span={6}>
            <FormItem {...formItemLayout} label='CEO姓名'>
              {getFieldDecorator('ceoName', {
                initialValue: item.ceoName
               })
                  (
                    <Input size='small' />
                  )
             }
           </FormItem>
         </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='CEO英文名'>
             {getFieldDecorator('ceoEname', {
               initialValue: item.ceoEname
              })
                 (
                   <Input size='small' />
                 )
            }
          </FormItem>
        </Col>

        <Col span={6}>
          <FormItem {...formItemLayout} label='CEO性别'>
            {getFieldDecorator('ceoSex', {
              initialValue: item.ceoSex
             })
                (
                  <Radio.Group>
                    <Radio value={1}>男</Radio>
                    <Radio value={0}>女</Radio>
                  </Radio.Group>
                )
             }
           </FormItem>
         </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='CEO生日'>
             {getFieldDecorator('ceoBirth', {
               initialValue: item.ceoBirth
              })
                 (
                   <DatePicker defaultValue={moment('2015/01/01', dateFormat)} format={dateFormat} style={{width:'100%'}} size='small'/>
                 )
             }
           </FormItem>
         </Col>
        </Row>

        <Row>
        <Col span={6}>
          <FormItem {...formItemLayout} label='是否有不良记录'>
            {getFieldDecorator('isBadRecord', {
              initialValue: item.isBadRecord ? [item.isBadRecord]:'',
             })
                (
                  <Cascader
                     placeholder='请选择'
                     size='small'
                     showSearch
                     style={{width:'100%'}}
                    // style={{marginTop:'6px'}}
                     options={[
                              {value:"1",label:'是'},
                              {value:"2",label:'否'},
                            ]}
                  />
                )
           }
         </FormItem>
       </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='成立日期'>
             {getFieldDecorator('establishDate', {
               initialValue: item.establishDate
              })
                 (
                   <Input size='small' />
                 )
            }
          </FormItem>
        </Col>

        <Col span={6}>
          <FormItem {...formItemLayout} label='营业范围'>
            {getFieldDecorator('businessScope', {
              initialValue: item.businessScope
             })
                (
                  <Input size='small' />
                )
             }
           </FormItem>
         </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='客户情况简介'>
             {getFieldDecorator('customerProfile', {
               initialValue: item.customerProfile
              })
                 (
                   <Input size='small' />
                 )
             }
           </FormItem>
         </Col>
        </Row>

        <Row>
          <Col span={6}>
            <FormItem {...formItemLayout} label='经营开始日期'>
              {getFieldDecorator('businessStartDate', {
                initialValue: item.businessStartDate
               })
                  (
                    <Input size='small' />
                  )
             }
           </FormItem>
         </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='经营结束日期'>
             {getFieldDecorator('businessEndDate', {
               initialValue: item.businessEndDate
              })
                 (
                   <Input size='small' />
                 )
            }
          </FormItem>
        </Col>

        <Col span={6}>
          <FormItem {...formItemLayout} label='代表处序号'>
            {getFieldDecorator('representOfficeCode', {
              initialValue: item.representOfficeCode
             })
                (
                  <Input size='small' />
                )
             }
           </FormItem>
         </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='代表处代表人数'>
             {getFieldDecorator('representativeNum', {
               initialValue: item.representativeNum
              })
                 (
                   <Input size='small' />
                 )
             }
           </FormItem>
         </Col>
        </Row>

        <Row>
          <Col span={6}>
            <FormItem {...formItemLayout} label='投资方'>
              {getFieldDecorator('investor', {
                initialValue: item.investor
               })
                  (
                    <Input size='small' />
                  )
             }
           </FormItem>
         </Col>


         <Col span={6}>
           <FormItem {...formItemLayout} label='组织机构代码'>
             {getFieldDecorator('organizationCode', {
               initialValue: item.organizationCode
              })
                 (
                   <Input size='small' />
                 )
            }
          </FormItem>
        </Col>

        <Col span={6}>
          <FormItem {...formItemLayout} label='开户行'>
            {getFieldDecorator('depositBank', {
              rules: [
                 {
                 required: true , message:'请输入英文形式 !',
                 },
              ],
              initialValue: item.depositBank
             })
                (
                  <Input size='small' placeholder='英文形式' />
                )
             }
           </FormItem>
         </Col>

         <Col span={6}>
           <FormItem {...formItemLayout} label='操作人'>
             {getFieldDecorator('operator', {
               rules: [
                  {
                  required: true , message:'不能为空 !',
                  },
               ],
               initialValue: item.operator
              })
                 (
                   <Input size='small' />
                 )
             }
           </FormItem>
         </Col>
        </Row>
      </Toggles>
    </Modal>

  )
}

modal.propTypes = {
  form: PropTypes.object.isRequired,
  type: PropTypes.string,
  item: PropTypes.object,
  onOk: PropTypes.func,
}

export default Form.create()(modal)
